fix(db): fully reconcile retrieval_owner_matches drift + harden PUBLIC-execute on retrieval helpers#403
Merged
Conversation
…sql -> pg_catalog) schema.sql declared `set search_path = public, pg_temp` for retrieval_owner_matches while both live and the migrations (20260705210000, 20260708150000) use `public, pg_catalog`. schema.sql was the sole outlier, so a fresh schema.sql replay diverged from live on this function's def_hash — noise the drift detector would flag. Verified read-only against live (project sjrfecxgysukkwxsowpy) via schema_drift_snapshot(): live body is byte-identical and uses `public, pg_catalog` (def_hash 1d88b539bded5aa40393125f672b8cab). Changes (behaviour-identical — the body references nothing schema-qualified; pg_catalog is the safer choice for an immutable function): - schema.sql: pg_temp -> pg_catalog for retrieval_owner_matches. - drift-manifest.json: def_hash -> live's value; schema_sha256 recomputed (normalizedSchemaSha256 of the edited schema.sql). - drift-allowlist.json: the entry mislabelled this tiny boolean helper as a "live-ahead richer-body" RPC (copy-paste from match_document_chunks et al.). Narrowed to the real remaining drift: the PUBLIC-execute ACL, same posture as search_document_chunks (owner-managed hardening; revoke on live to close). - docs/database-drift-detection.md: removed retrieval_owner_matches from the "forward-codify live bodies" backlog group; noted the partial reconciliation. Manifest was hand-edited (Docker drift:manifest replay OOMs in this env, per the deploy-status notes); a reviewer can run `npm run drift:manifest` to confirm the snapshot def_hash + schema_sha256 match a fresh replay. tests/supabase-schema.test.ts: 42/42 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Updates to Preview Branch (claude/reconcile-retrieval-owner-search-path) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
BigSimmo
enabled auto-merge (squash)
July 8, 2026 14:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fully reconciles the
retrieval_owner_matchesschema/live drift and closes the related PUBLIC-execute drift onsearch_document_chunks. Two logically-grouped commits.1. search_path reconciliation (commit f7e3d91)
schema.sqldeclaredset search_path = public, pg_tempforretrieval_owner_matches, while live and both migrations (20260705210000,20260708150000) usepublic, pg_catalog.schema.sqlwas the sole outlier → fresh-replaydef_hashdiverged from live. Verified read-only against live (sjrfecxgysukkwxsowpy) viaschema_drift_snapshot(): body byte-identical,def_hash 1d88b539…. Behaviour-identical (pg_catalogis the safer choice for animmutablefunction).supabase/schema.sql—pg_temp→pg_catalog(this fn only).supabase/drift-manifest.json—def_hash→ live value;schema_sha256recomputed.2. PUBLIC-execute hardening — applied to live (commit ba45ed2)
Both
retrieval_owner_matchesandsearch_document_chunksretained the default PUBLICEXECUTEgrant on live, drifting from schema.sql's declared blanket posture (revoke execute on all functions in schema public from public, anon, authenticated+ grant toservice_role).Safety verified before applying — both are server-only, so revoking PUBLIC is behaviour-neutral:
search_document_chunksis called via the service-role admin client (src/app/api/documents/[id]/search/route.ts), which keeps execute.retrieval_owner_matchesis only invoked nested inside retrieval RPCs that run asservice_role.Applied to live via Supabase MCP (recorded version
20260708150150); verified read-only that both ACLs are now{postgres,service_role}(PUBLIC removed), matching the manifest. Security advisor: no lints.supabase/migrations/20260708150150_harden_retrieval_public_execute.sql— idempotent; no-op on schema.sql-provisioned/preview envs. Version matches live's recorded migration history (no version-stamp drift).supabase/drift-allowlist.json— removed both now-resolved entries.docs/database-drift-detection.md— recorded the reconciliation.Scope note
Three other functions carry the same PUBLIC-execute drift (
document_summary_text(uuid),detect_legacy_ivfflat_indexes(),set_document_embedding_field_content_hash()— the last a trigger fn whose ACL is cosmetic). Left out of this PR: they weren't in scope and their nested-call safety wasn't individually verified. Same one-line pattern applies if you want a follow-up.Verification
tests/supabase-schema.test.ts— 42/42 pass.prettier --checkon all edited files — pass.schema_drift_snapshot()/pg_proc.proacl(read-only), security advisor clean.check:drift(needs live service-role key in env),drift:manifest(Docker OOM here) — both covered by the read-only live verification. Manifest was hand-edited (documented, same as fix(db): remove phantom ingestion_job_stages.job_id FK to match live (R24e) #389).Clinical Governance Preflight
DB schema/grants only; no clinical-output behaviour change. Supabase target remains
Clinical KB Database(sjrfecxgysukkwxsowpy). The one live change is a privilege revoke (tightening), applied via MCP and verified; service-role access remains server-only. No patient-data workflow touched.🤖 Generated with Claude Code